package leetcode.part3;

import org.junit.Test;

import java.util.*;

public class S73 {
    public void setZeroes(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        Set<Integer> rowFlag = new HashSet<>();
        Set<Integer> colFlag = new HashSet<>();

        // 对存在0的行列进行标记
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (matrix[i][j] == 0) {
                    rowFlag.add(i);
                    colFlag.add(j);
                }
            }

        }
        // 将记录的行列清0
        for (Integer row : rowFlag) {
            for (int col = 0; col < n; col++) {
                matrix[row][col] = 0;
            }
        }

        for (Integer col : colFlag) {
            for (int row = 0; row < m; row++) {
                matrix[row][col] = 0;
            }
        }
    }

    @Test
    public void test() {
        int[][] matrix = {{0, 1, 2, 0}, {3, 4, 5, 2}, {1, 3, 1, 5}};
        setZeroes(matrix);
        System.out.println(Arrays.deepToString(matrix));
    }
}
